home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / Math / tanh.c < prev   
C/C++ Source or Header  |  1990-04-07  |  3KB  |  104 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *                              N O T I C E                             *
  4.  *                                                                      *
  5.  *                      Copyright Abandoned, 1987, Fred Fish            *
  6.  *                                                                      *
  7.  *      This previously copyrighted work has been placed into the       *
  8.  *      public domain by the author (Fred Fish) and may be freely used  *
  9.  *      for any purpose, private or commercial.  I would appreciate     *
  10.  *      it, as a courtesy, if this notice is left in all copies and     *
  11.  *      derivative works.  Thank you, and enjoy...                      *
  12.  *                                                                      *
  13.  *      The author makes no warranty of any kind with respect to this   *
  14.  *      product and explicitly disclaims any implied warranties of      *
  15.  *      merchantability or fitness for any particular purpose.          *
  16.  *                                                                      *
  17.  ************************************************************************
  18.  */
  19.  
  20. /*
  21.  *  FUNCTION
  22.  *
  23.  *      tanh   double precision hyperbolic tangent
  24.  *
  25.  *  KEY WORDS
  26.  *
  27.  *      tanh
  28.  *      machine independent routines
  29.  *      math libraries
  30.  *
  31.  *  DESCRIPTION
  32.  *
  33.  *      Returns double precision hyperbolic tangent of double precision
  34.  *      floating point number.
  35.  *
  36.  *  USAGE
  37.  *
  38.  *      double tanh (x)
  39.  *      double x;
  40.  *
  41.  *  REFERENCES
  42.  *
  43.  *      Fortran IV plus user's guide, Digital Equipment Corp. pp B-5
  44.  *
  45.  *  RESTRICTIONS
  46.  *
  47.  *      For precision information refer to documentation of the
  48.  *      floating point library routines called.
  49.  *      
  50.  *  PROGRAMMER
  51.  *
  52.  *      Fred Fish
  53.  *
  54.  *  INTERNALS
  55.  *
  56.  *      Computes hyperbolic tangent from:
  57.  *
  58.  *              tanh(x) = 1.0 for x > TANH_MAXARG
  59.  *                      = -1.0 for x < -TANH_MAXARG
  60.  *                      =  sinh(x) / cosh(x) otherwise
  61.  *
  62.  */
  63.  
  64. #include <stdio.h>
  65. #include "pml.h"
  66.  
  67. static char funcname[] = "tanh";
  68.  
  69.  
  70. double tanh (x)
  71. double x;
  72. {
  73.     struct exception xcpt;
  74.     int positive;
  75.     extern double sinh ();
  76.     extern double cosh ();
  77.  
  78.     DBUG_ENTER (funcname);
  79.     DBUG_3 ("tanhin", "arg %le", x);
  80.     if (x > TANH_MAXARG || x < -TANH_MAXARG) {
  81.         if (x > 0.0) {
  82.             positive = 1;
  83.         } else {
  84.             positive = 0;
  85.         }
  86.         xcpt.type = PLOSS;
  87.         xcpt.name = funcname;
  88.         xcpt.arg1 = x;
  89.         if (!matherr (&xcpt)) {
  90.             fprintf (stderr, "%s: PLOSS error\n", funcname);
  91.             errno = ERANGE;
  92.             if (positive) {
  93.                 xcpt.retval = 1.0;
  94.             } else {
  95.                 xcpt.retval = -1.0;
  96.             }
  97.         }
  98.     } else {
  99.         xcpt.retval = sinh (x) / cosh (x);
  100.     }
  101.     DBUG_3 ("tanhout", "result %le", xcpt.retval);
  102.     return (xcpt.retval);
  103. }
  104.